#include "widget.h"
#include "ui_widget.h"
#include<QLabel>
#include<QRect>
#include<QResizeEvent>
#include<thread>
#include<QTimer>
#include<QDate>
#include<QDebug>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    // 设置标签为图片
//    ui->label->setPixmap(QPixmap(":/mm.jpg"));
//    QRect rect=this->geometry();
//    ui->label->setGeometry(rect.x(),rect.y(),rect.width(),rect.height());
//    ui->label->setScaledContents(true);//自动拉伸

    //设置文本对齐方式
//    ui->label_2->setText("你憨帅啊啊");
//    ui->label_2->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
//    ui->label_2->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
//    ui->label_2->setAlignment(Qt::AlignRight|Qt::AlignVCenter);

    //设置文本自动换行
//    ui->label_2->setText("你还红红火火恍恍惚惚哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈就还好红红火火恍恍惚惚哈哈哈哈哈");
//    ui->label_2->setWordWrap(true);
    //设置首行缩进
//    ui->label_2->setIndent(50);
    //设置边框距
//    ui->label_2->setAlignment(Qt::AlignTop|Qt::AlignLeft);
//    ui->label_2->setMargin(30);

    //绑定伙伴
//    ui->label_3->setBuddy(ui->radioButton);
//    ui->label_4->setBuddy(ui->radioButton_2);



    //10秒倒计时
//    timer=new QTimer(this);
//    connect(timer,&QTimer::timeout,this,&Widget::handle);
//    timer->start(1000);


    //进度条
//    timer=new QTimer(this);
//    connect(timer,&QTimer::timeout,this,&Widget::update_progres);
//    timer->start(50);
    //改变进度条颜色
//    ui->progressBar->setStyleSheet("QProgressBar::chunk {background-color:#ff0000;}");
//    ui->progressBar->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);

}

Widget::~Widget()
{
    delete ui;
}

void Widget::resizeEvent(QResizeEvent *event)
{
    ui->label->setGeometry(0,0,event->size().width(),event->size().height());
}

void Widget::handle()
{
    int value=ui->lcdNumber->intValue();
    if(value<=0)
    {
        timer->stop();
        return;
    }
    ui->lcdNumber->display(value-1);
}

void Widget::update_progres()
{
    int value=ui->progressBar->value();
    if(value>=100)
    {
        timer->stop();
        return;
    }
    ui->progressBar->setValue(value+1);
}


void Widget::on_calendarWidget_selectionChanged()
{
    QDate date=ui->calendarWidget->selectedDate();
    qDebug()<<date;

    ui->label_5->setText(date.toString());

}
